]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Add st_texture_cache_load
authorColin Walters <walters@verbum.org>
Tue, 9 Feb 2010 21:53:59 +0000 (16:53 -0500)
committerColin Walters <walters@verbum.org>
Mon, 8 Mar 2010 20:50:59 +0000 (15:50 -0500)
Function for caching texture data from an arbitrary origin.

https://bugzilla.gnome.org/show_bug.cgi?id=607500

src/st/st-texture-cache.c
src/st/st-texture-cache.h

index 84e2a9b244eaa99b1f20b75adf22bb0b74c9fcf8..ad33e52b498fd195c0973a4e2032f36d09fac2e1 100644 (file)
@@ -830,6 +830,45 @@ st_texture_cache_bind_pixbuf_property (StTextureCache    *cache,
   return CLUTTER_ACTOR(texture);
 }
 
+/**
+ * st_texture_cache_load:
+ * @cache: A #StTextureCache
+ * @key: Arbitrary string used to refer to item
+ * @policy: Caching policy
+ * @load: Function to create the texture, if not already cached
+ * @data: User data passed to @load
+ * @error: A #GError
+ *
+ * Load an arbitrary texture, caching it.  The string chosen for @key
+ * should be of the form "type-prefix:type-uuid".  For example,
+ * "url:file:///usr/share/icons/hicolor/48x48/apps/firefox.png", or
+ * "stock-icon:gtk-ok".
+ *
+ * Returns: (transfer full): A newly-referenced handle to the texture
+ */
+CoglHandle
+st_texture_cache_load (StTextureCache       *cache,
+                       const char           *key,
+                       StTextureCachePolicy  policy,
+                       StTextureCacheLoader  load,
+                       void                 *data,
+                       GError              **error)
+{
+  CoglHandle texture;
+
+  texture = g_hash_table_lookup (cache->priv->keyed_cache, key);
+  if (!texture)
+    {
+      texture = load (cache, key, data, error);
+      if (texture)
+        g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texture);
+      else
+        return COGL_INVALID_HANDLE;
+    }
+  cogl_texture_ref (texture);
+  return texture;
+}
+
 /**
  * create_texture_and_ensure_request:
  * @cache:
index 2e6dfd12de08dcf43d79a7a05d59a98df3dd2a57..bfbfabbac2acc9e0c37d6baa50d251b1102d832c 100644 (file)
@@ -101,6 +101,15 @@ ClutterActor *st_texture_cache_load_from_raw  (StTextureCache    *cache,
                                                int                size,
                                                GError           **error);
 
+typedef CoglHandle (*StTextureCacheLoader) (StTextureCache *cache, const char *key, void *data, GError **error);
+
+CoglHandle st_texture_cache_load (StTextureCache       *cache,
+                                  const char           *key,
+                                  StTextureCachePolicy  policy,
+                                  StTextureCacheLoader  load,
+                                  void                 *data,
+                                  GError              **error);
+
 gboolean st_texture_cache_pixbuf_equal (StTextureCache *cache, GdkPixbuf *a, GdkPixbuf *b);
 
 #endif /* __ST_TEXTURE_CACHE_H__ */